package cn.stylefeng.guns.modular.constant.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.constant.entity.Constant;
import cn.stylefeng.guns.modular.constant.model.params.ConstantParam;
import cn.stylefeng.guns.modular.constant.service.ConstantService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 参数配置控制器
 *
 * @author liuqiang
 * @Date 2020-02-14 21:30:42
 */
@RestController
@RequestMapping("/constant")
public class ConstantController extends BaseController {

    @Autowired
    private ConstantService constantService;

    /**
     * 新增接口
     *
     * @author liuqiang
     * @Date 2020-02-14
     */
    @PostMapping("/addItem")
    public ResponseData addItem(@RequestBody ConstantParam constantParam) {
        this.constantService.add(constantParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author liuqiang
     * @Date 2020-02-14
     */
    @PostMapping("/editItem")
    public ResponseData editItem(@RequestBody ConstantParam constantParam) {
        this.constantService.update(constantParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author liuqiang
     * @Date 2020-02-14
     */
//    @RequestMapping("/delete")
//    @ResponseBody
    public ResponseData delete(ConstantParam constantParam) {
        this.constantService.delete(constantParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author liuqiang
     * @Date 2020-02-14
     */
    @GetMapping("/detail")
    public ResponseData detail(ConstantParam constantParam) {
        Constant detail = this.constantService.getById(constantParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author liuqiang
     * @Date 2020-02-14
     */
    @GetMapping("/list")
    public LayuiPageInfo list(ConstantParam constantParam) {
        return this.constantService.findPageBySpec(constantParam);
    }

}


